'use strict';

const BaseService = require('./base');

class SectionService extends BaseService {
  constructor(...props) {
    super('Booklet', ...props)
  }
  //通过用户id获取书
  async findBookletByUserId(user_id) {
    const { primary_model, ctx } = this;
    return await ctx.model.UserBooklet.findAll({
      where: {status: '1', user_id},
      attributes: ['id', 'user_id', 'booklet_id'],
      include: {
        model: ctx.model.Booklet,
        attributes: ['id', 'name', 'css_url', 'cover_url'],
      }
    })
  }
  //查看是否有该书
  async findBookletByName(name) {
    const { primary_model, ctx } = this;
    return await primary_model.findOne({
      where: {status: '1', name},
    })
  }
}

module.exports = SectionService;
